#include "condition.h"

using namespace wolv::condition;

Condition::Condition(int op, Variable lho, Variable rho, const std::string& success_action, const std::string& fail_action)
:op_(op), lho_(lho), rho_(rho), successAction_(success_action), failAction_(fail_action), pContext_(0)
{

}

wolv::condition::Condition::Condition()
:op_(0), lho_(wolv::weakType::nullType), rho_(wolv::weakType::nullType), successAction_(""), failAction_(""), pContext_(0)
{

}

const std::string Condition::Exec()
{
	bool condition = false;

	lho_.SetConext(pContext_);
	rho_.SetConext(pContext_);

	switch (op_)
	{
	case E:
		condition = lho_ == rho_;
		break;
	case NE:
		condition = lho_ != rho_;
		break;
	case GT:
		condition = lho_ > rho_;
		break;
	case GET:
		condition = lho_ >= rho_;
		break;
	case LT:
		condition = lho_ < rho_;
		break;
	case LET:
		condition = lho_ <= rho_;
		break;
	case IN:
		condition = lho_.in(rho_);
		break;
	default:
		return "";
		break;
	}

	if (condition)
	{
		return successAction_;
	}
	else
	{
		return failAction_;
	}

	return "";
}



void wolv::condition::Condition::SetContext( LocalContext* pContext )
{
	pContext_ = pContext;
	lho_.SetConext(pContext_);
	rho_.SetConext(pContext_);
}
